python libs for all vis things


In [6]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['show', 'figure']
`%matplotlib` prevents importing * from pylab and numpy

In [7]:
t = arange(0.0, 1.0, 0.01)

y1 = sin(2*pi*t)
y2 = sin(2*2*pi*t)

import pandas as pd

df = pd.DataFrame({'t': t, 'y1': y1, 'y2': y2})
df.head(10)


Out[7]:
t y1 y2
0 0.00 0.000000 0.000000
1 0.01 0.062791 0.125333
2 0.02 0.125333 0.248690
3 0.03 0.187381 0.368125
4 0.04 0.248690 0.481754
5 0.05 0.309017 0.587785
6 0.06 0.368125 0.684547
7 0.07 0.425779 0.770513
8 0.08 0.481754 0.844328
9 0.09 0.535827 0.904827

In [8]:
from bokeh.plotting import figure, output_notebook, show

# output inline with notebook
output_notebook()

# create a new plot with a title and axis labels
p = figure(title="simple sine example", x_axis_label='t', y_axis_label='sin(2*pi*t)')

# add a line renderer with legend and line thickness
p.line(t, sin(2*pi*t), legend="Temp.", line_width=2)

# show the results
show(p)


BokehJS successfully loaded.
Out[8]:
<bokeh.io._CommsHandle at 0x10c90a1d0>

In [11]:
# this uses Bokeh for plotting + ipywidgets for widgets
# translation: no Bokeh server required

from ipywidgets import interact
import numpy as np

from bokeh.io import push_notebook
from bokeh.plotting import figure, show, output_notebook

x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)

output_notebook()

p = figure(title="simple curvy example", plot_height=300, plot_width=600, y_range=(-5,5))
r = p.line(x, y, color="#2222aa", line_width=3)

def update(f, w=1, A=1, phi=0):
    if   f == "sin": func = np.sin
    elif f == "cos": func = np.cos
    elif f == "tan": func = np.tan
    r.data_source.data['y'] = A * func(w * x + phi)
    push_notebook() # only updates *last* shown object
    
interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,5), phi=(0, 20, 0.1))
show(p)


Out[11]:
<bokeh.io._CommsHandle at 0x1029c0c10>

In [12]:
from bokeh.plotting import figure, output_file, show

# prepare some data
x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y0 = [i**2 for i in x]
y1 = [10**i for i in x]
y2 = [10**(i**2) for i in x]

output_notebook()

# create a new plot
p = figure(
   tools="pan,box_zoom,reset,save",
   y_axis_type="log", y_range=[0.001, 10**11], title="log axis example",
   x_axis_label='sections', y_axis_label='particles'
)

# add some renderers
p.line(x, x, legend="y=x")
p.circle(x, x, legend="y=x", fill_color="white", size=8)
p.line(x, y0, legend="y=x^2", line_width=3)
p.line(x, y1, legend="y=10^x", line_color="red")
p.circle(x, y1, legend="y=10^x", fill_color="red", line_color="red", size=6)
p.line(x, y2, legend="y=10^x^2", line_color="orange", line_dash="4 4")

# show the results
show(p)


BokehJS successfully loaded.
Out[12]:
<bokeh.io._CommsHandle at 0x10bd1fc50>

others to check out